<?php
namespace app\index\controller;

use think\Request;

class Recharge extends Base
{


    public function buy($id){

        $product = model('recharge')->where('id',$id)->find();
        $this->assign('product',$product);
        return view('buy');
    }


    public function saveOrder(){
        $id = Request::instance()->get('id');
        $product = model('recharge')->where('id',$id)->find();
        if($product){
            $data['buyUid'] = $this->uid;
            $data['productId'] = $id;
            $data['otype'] = 1;
            $data['status'] = 0;
            $data['totalFee'] =  100*$product->salePrice;
            $data['createTime'] = time();
            $data['payment_order_id'] = date('YmdHis').rand(1000,9999);
            $id = model('order')->insertGetId($data);
            $this->redirect('pay/weixin/pay',['id'=>$id]);
        }
        else{
            die('没有找到商品');
        }
    }

}
